﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using System.Data.OleDb;

namespace Cadastro
{
    class PrincipalClass
    {
        public DataSet PesquisaGenerica(string SQL)
        {
            DataSet dSet = new DataSet();
            string stringConn = "Server=localhost; DATABASE=cadastro; UID=gabriel; PASSWORD=deadspace123;";
            MySqlConnection conn = new MySqlConnection(stringConn);
            MySqlCommand cmd = new MySqlCommand(SQL, conn);
            MySqlDataAdapter objAdapter = new MySqlDataAdapter(cmd);
            conn.Open();
            objAdapter.Fill(dSet);
            conn.Close();
            return dSet;
        }
        public void ExecSql (string Sql)
        {
            string stringConn = "Server=localhost; DATABASE=cadastro; UID=gabriel; PASSWORD=deadspace123;";
            MySqlConnection conn = new MySqlConnection(stringConn);
            conn.Open();
            MySqlCommand command = new MySqlCommand(Sql,conn);
            command.ExecuteNonQuery();
            conn.Close();
        }
        public int GetID (string Tabela, string Coluna)
        {
            DataSet ds = new DataSet();
            int cont = 0;
            ds = PesquisaGenerica("SELECT " + Coluna + " FROM " + Tabela);

            for (cont = 0; cont < ds.Tables[0].Rows.Count; cont++)
            {
                if (ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                else if (cont == Convert.ToInt32(ds.Tables[0].Rows[cont][0]))
                {
                    continue;
                }                
            }
            return cont;
        }
    }
}
